<template>
  <div class="tab-bar-item" @click="itemClick" :class="{'item-active': isActive}">
    <div class="item-icon">
      <slot v-if="isActive" name="item-icon-active"></slot>
      <slot v-else name="item-icon"></slot>
    </div>
    <div class="item-text">
      <slot name="item-text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabBarItem",
  props: {
    path: {
      type: String
    }
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) > -1;
    }
  },
  methods: {
    itemClick() {
      this.$router.replace(this.path)
    }
  }
}
</script>

<style scoped>
.tab-bar-item {
  flex: 1;
  height: 49px;
  text-align: center;
}

.tab-bar-item .item-icon img {
  width: 22px;
  height: 22px;
  margin-top: 5px;
  vertical-align: middle;

}

.tab-bar-item .item-text {
  font-size: var(--font-size);
  margin-top: 3px;
}

.item-active {
  color: var(--color-high-text);
}

</style>